package com.gigi.searchcenterbackendmaster.controller;

import com.gigi.searchcenterbackendmaster.common.BaseResponse;
import com.gigi.searchcenterbackendmaster.manager.SearchFacade;
import com.gigi.searchcenterbackendmaster.model.request.SearchRequest;
import com.gigi.searchcenterbackendmaster.model.request.SearchSuggestRequest;
import com.gigi.searchcenterbackendmaster.model.vo.SearchVO;
import com.gigi.searchcenterbackendmaster.service.ArticleService;
import com.gigi.searchcenterbackendmaster.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Gigi
 * @date 2024/8/17 16:14
 */
@Api(tags = "搜索")
@RestController
@RequestMapping("search")
public class SearchController {

    @Resource
    private SearchFacade searchFacade;

    @Resource
    private ArticleService articleService;

    @ApiOperation(value = "聚合搜索")
    @PostMapping("all")
    public BaseResponse<SearchVO> searchAll(@RequestBody SearchRequest request) {
        return ResultUtil.success(searchFacade.searchAll(request));
    }

    @ApiOperation(value = "搜索建议")
    @PostMapping("suggest")
    public BaseResponse<List<String>> suggest(@RequestBody SearchSuggestRequest request) {
        return ResultUtil.success(articleService.suggest(request));
    }

}
